<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class General extends CI_Controller {
    public function __construct() {
        parent::__construct();
        $this->load->helper('url');
        $this->load->library('session');
    }
    public function index() {
        if($this->session->userdata('barangay_id') != '' || $this->session->userdata('barangay_id') != null) {
            if($this->session->userdata('user_resp') == "admin") { 
                $this->load->view('general');
            } else {
                header('Location: ' . base_url());
            }
        } else {
            header('Location: ' . base_url());
        }
    }
    public function getdesc() {
        $this->load->model('General_model');
        $result['desc'] = $this->General_model->getDesc();
        print json_encode($result);
    }
    public function signup() {
        $this->load->model('General_model');
        $result['barangayadd'] = $this->General_model->signUp();
        print json_encode($result);
    }
    public function update() {
        if($this->session->userdata('user_resp') == "admin") {
            $this->load->model('General_model');
            $result['barangay_update'] = $this->General_model->update();
        }
    }
    public function changedesc() {
        if($this->session->userdata('user_resp') == "admin") {
            $this->load->model('General_model');
            $result['barangay_description'] = $this->General_model->changeDesc();
        }
    }
    public function getprovince() {
        $this->load->model('General_model');
        $result['provinces'] = $this->General_model->getProvince();
        print json_encode($result);
    }
    public function getmunicipality() {
        $this->load->model('General_model');
        $result['municipalities'] = $this->General_model->getMunicipality($this->input->post('p_id'));
        print json_encode($result);
    }
    public function getbarangay() {
        $this->load->model('General_model');
        $result['barangays'] = $this->General_model->getBarangay($this->input->post('m_id'));
        //$result['barangays'] = $this->input->post('m_id');
        print json_encode($result);
    }
}